package com.test;

/*
public class Example03 {
    public static void main(String[] args) {
        class Student {
            String name;        // 声明String类型的变量name
            int age;            // 声明int类型的变量age
            String sex;        // 声明String类型的变量sex

            // 定义 read () 方法
            void read() {
                System.out.println("大家好，我是" + name + ",我在看书!");
            }
        }
    }
}

 */

/*
class Student {
    String name;     // 声明姓名属性

    void read() {
        System.out.println("大家好，我是" + name + ",我在看书!");
    }
}

public class Example03 {

    public static void main(String[] args) {
        Student stu = new Student();
        stu.name = "李华";
        stu.read();
    }
}

 */

/*
class Student {
    String name;
    int age;

    void read() {
        System.out.println("大家好，我是" + name + "，年龄" + age);
    }
}

public class Example03 {
    public static void main(String[] args) {
        Student stu1 = new Student();
        Student stu2 = null;
        stu2=stu1;
        stu1.name = "小明";
        stu1.age = 20;
        stu2.age = 50;
        stu1.read();
        stu2.read();
    }
}

 */

/*
class Student{
    String name;
    int age;
    void read(){
        System.out.println("大家好，我是"+name+"，年龄"+age);
    }
}
public class Example03 {
    public static void main(String[] args){
        Student stu= new Student();
        stu.name="张三";
        stu.age=-19;
        stu.read();
    }
}

 */


/*
class Student{
    private String name;        	// 声明姓名属性
    private  int age;           	// 声明年龄属性
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        if(age < 0){
            System.out.println("您输入的年龄有误！");
        } else {
            this.age = age;
        }
    }
    public void read() {
        System.out.println("大家好，我是"+name+"，年龄"+age);
    }
}
public class Example03 {
    public static void main(String[] args) {
        Student stu = new Student();		// 创建学生对象
        stu.setName("张三");	              	// 为对象的name属性赋值
        stu.setAge(-18);	               	// 为对象的age属性赋值
        stu.read();	                        	// 调用对象的方法
    }
}

 */

/*
class Student{
    public Student() {
        System.out.println("调用了无参构造方法");
    }
}
public class Example03 {
    public static void main(String[] args) {
        System.out.println("声明对象...");
        Student stu = null;           		//声明对象
        System.out.println("实例化对象...");
        stu = new Student();     			//实例化对象
    }
}

 */

/*
class Student {
    private String name;
    private int age;

    public Student(String n, int a) {
        name = n;
        age = a;
        System.out.println("调用了有参构造方法");
    }

    public void read() {
        System.out.println("我是:" + name + ",年龄:" + age);
    }
}

public class Example03 {
    public static void main(String[] args) {
        Student stu = new Student("张三", 16);
        stu.read();
    }
}

 */


/*
class Student {
    private String name;
    private int age;

    public Student() {
    }

    public Student(String n) {
        name = n;
        System.out.println("调用了一个参数的构造方法");
    }

    public Student(String n, int a) {
        name = n;
        age = a;
        System.out.println("调用了两个参数的构造方法");
    }

    public void read() {
        System.out.println("我是:" + name + ",年龄:" + age);
    }
}

public class Example03 {
    public static void main(String[] args){
        Student stu1=new Student("李华");
        Student stu2=new Student("张三",16);
        stu1.read();
        stu2.read();

    }
}

 */

/*
class Student {
    private String name;
    private int age;
    // 定义构造方法
    public Student(String name,int age) {
        name = name;
        age = age;
    }
    public String read(){
        return "我是:"+name+",年龄:"+age;
    }
}
public class Example03 {
    public static void main(String[] args) {
        Student stu = new Student("张三", 18);
        System.out.println(stu.read());
    }
}

 */

/*
class Student {
    private String name;
    private int age;
    // 定义构造方法
    public Student(String name,int age) {
        this.name = name;
        this.age = age;
    }
    public String read(){
        return "我是:"+name+",年龄:"+age;
    }
}
public class Example03 {
    public static void main(String[] args) {
        Student stu = new Student("张三", 18);
        System.out.println(stu.read());
    }
}

 */

/*
class Student {
    private String name;
    private int age;
    public Student () {
        System.out.println("调用了无参的构造方法");
    }
    public Student (String name,int age) {
        this();                  // 调用无参的构造方法
        this.name = name;
        this.age = age;
    }
    public String read(){
        return "我是:"+name+",年龄:"+age;
    }
}
public class Example03 {
    public static void main(String[] args) {
        Student stu = new Student("张三",18);    // 实例化 Student对象
        System.out.println(stu.read());
    }
}

 */

/*
class Student {
    String name;                                        // 定义name属性
    int age;                                            // 定义age属性
    String school = "A大学";                            // 定义school属性

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public void info() {
        System.out.println("姓名:" + this.name + "，年龄:" + this.age +
                "，学校:" + school);
    }
}

public class Example03 {
    public static void main(String[] args) {
        Student stu1 = new Student("张三", 18);    // 创建学生对象
        Student stu2 = new Student("李四", 19);
        Student stu3 = new Student("王五", 20);
        stu1.info();
        stu2.info();
        stu3.info();
        //修改stu1对象的school的值
        stu1.school = "B大学";
        System.out.println("修改stu1学生对象的学生信息为B大学后");
        stu1.info();
        stu2.info();
        stu3.info();
    }
}

 */

/*
class Student {
    String name;                    					// 定义name属性
    int age;                         					// 定义age属性
    static String school = "A大学";    						// 定义school属性
    public Student(String name,int age){
        this.name = name;
        this.age = age;
    }
    public void info(){
        System.out.println("姓名:" + this.name+"，年龄:" +this. age+
                "，学校:" + school);
    }
}
public class Example03 {
    public static void main(String[] args) {
        Student stu1 = new Student("张三",18);    // 创建学生对象
        Student stu2 = new Student("李四",19);
        Student stu3 = new Student("王五",20);
        stu1.info();
        stu2.info();
        stu3.info();
        stu1.school = "B大学";//修改stu1对象的school的值
        System.out.println("修改stu1学生对象的学生信息为B大学后");
        stu1.info();
        stu2.info();
        stu3.info();
    }
}

 */

/*
class Student {
    private static String school = "A大学";            // 定义school属性
    private String name;                                // 声明name属性
    private int age;                                    // 声明age属性

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public static String getSchool() {
        return school;
    }

    public static void setSchool(String s) {
        school = s;
    }

    public void info() {
        System.out.println("姓名:" + this.name + "，年龄:" + this.age +
                "，学校:" + school);
    }
}

class Example03 {
    public static void main(String[] args) {
        Student stu1 = new Student("张三", 18);      // 创建学生对象stu1
        Student stu2 = new Student("李四", 19);      // 创建学生对象stu2
        Student stu3 = new Student("王五", 20);      // 创建学生对象stu3
        System.out.println("----修改前----");
        stu1.info();
        stu2.info();
        stu3.info();
        System.out.println("----修改后----");
        Student.setSchool("B大学");              //为静态属性school重新赋值
        stu1.info();
        stu2.info();
        stu3.info();
    }
}
 */


/*
class Student{
    String name;    //成员属性
    {
        System.out.println("我是构造代码块");
    }
    static {
        System.out.println("我是静态代码块");
    }
    public Student(){   //构造方法
        System.out.println("我是Student类的构造方法");
    }
}
class Example03{
    public static void main(String[] args) {
        Student stu1 = new Student();
        Student stu2 = new Student();
        Student stu3 = new Student();
    }
}

 */